/**************************************************************************************************
  Filename:       zcl_SalesBox_data.c
  Revised:        $Date: 2014-05-12 13:14:02 -0700 (Mon, 12 May 2014) $
  Revision:       $Revision: 38502 $


  Description:    Zigbee Cluster Library - sample device application.


  Copyright 2006-2014 Texas Instruments Incorporated. All rights reserved.

  IMPORTANT: Your use of this Software is limited to those specific rights
  granted under the terms of a software license agreement between the user
  who downloaded the software, his/her employer (which must be your employer)
  and Texas Instruments Incorporated (the "License").  You may not use this
  Software unless you agree to abide by the terms of the License. The License
  limits your use, and you acknowledge, that the Software may not be modified,
  copied or distributed unless embedded on a Texas Instruments microcontroller
  or used solely and exclusively in conjunction with a Texas Instruments radio
  frequency transceiver, which is integrated into your product.  Other than for
  the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  works of, modify, distribute, perform, display or sell this Software and/or
  its documentation for any purpose.

  YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.

  Should you have any questions regarding your right to use this Software,
  contact Texas Instruments Incorporated at www.TI.com.
**************************************************************************************************/

/*********************************************************************
 * INCLUDES
 */
#include "ZComDef.h"
#include "OSAL.h"
#include "AF.h"
#include "ZDConfig.h"

#include "zcl.h"
#include "zcl_general.h"
#include "zcl_ha.h"
#include "zcl_SalesBox_data.h"

/* SALESBOX_TODO: Include any of the header files below to access specific cluster data
#include "zcl_poll_control.h"
#include "zcl_electrical_measurement.h"
#include "zcl_diagnostic.h"
#include "zcl_meter_identification.h"
#include "zcl_appliance_identification.h"
#include "zcl_appliance_events_alerts.h"
#include "zcl_power_profile.h"
#include "zcl_appliance_control.h"
#include "zcl_appliance_statistics.h"
#include "zcl_hvac.h"
*/

#include "zcl_SalesBox.h"

/*********************************************************************
 * CONSTANTS
 */

#define SALESBOX_DEVICE_VERSION     0
#define SALESBOX_FLAGS              0

#define SALESBOX_HWVERSION          1
#define SALESBOX_ZCLVERSION         2
#define SALESBOX_APPLVERSION        0
#define SALESBOX_STACKVERSION       0

/*********************************************************************
 * TYPEDEFS
 */

/*********************************************************************
 * MACROS
 */

/*********************************************************************
 * GLOBAL VARIABLES
 */

// Global attributes
const uint16 zcl_clusterRevision_all = 0x0001;

// Basic Cluster
const uint8 zclSalesBox_ZCLVersion = SALESBOX_ZCLVERSION;
const uint8 zclSalesBox_APPLVersion = SALESBOX_APPLVERSION;
const uint8 zclSalesBox_StackVersion = SALESBOX_STACKVERSION;
const uint8 zclSalesBox_HWRevision = SALESBOX_HWVERSION;
const uint8 zclSalesBox_ManufacturerName[] = { 16, 'X','i','n','Y','i','G','o',' ',' ',' ',' ',' ',' ',' ',' ',' ' };
const uint8 zclSalesBox_ModelId[] = { 16, 'S','A','L','E','S','B','O','X',' ',' ',' ',' ',' ',' ',' ',' ' };
const uint8 zclSalesBox_DateCode[] = { 16, '2','0','1','9','0','6','3','1',' ',' ',' ',' ',' ',' ',' ',' ' };
const uint8 zclSalesBox_PowerSource = POWER_SOURCE_MAINS_1_PHASE;

uint8 zclSalesBox_LocationDescription[17] = { 16, ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' };
uint8 zclSalesBox_PhysicalEnvironment = 0;
uint8 zclSalesBox_DeviceEnable = DEVICE_ENABLED;

// Identify Cluster
uint16 zclSalesBox_IdentifyTime;

// On Off
bool zclSalesBox_OnOff;

//Level
uint8  zclSalesBox_LevelCurrentLevel;
uint16 zclSalesBox_LevelRemainingTime;
uint16 zclSalesBox_LevelOnOffTransitionTime;
uint8  zclSalesBox_LevelOnLevel;
uint16 zclSalesBox_LevelOnTransitionTime;
uint16 zclSalesBox_LevelOffTransitionTime;
uint8  zclSalesBox_LevelDefaultMoveRate;

//sales box
uint8  zclSalesBox_OpenedBox;
uint8  zclSalesBox_TotalBox;
uint8  zclSalesBox_LastBox;
uint32 zclSalesBox_BoxStatus;

//sensor
uint16 zclSensor_IdentifyTime;
bool zclSensor_OnOff;

CONST zclManuCodeTab_t zclSalesBox_ManuCodeArray[] = 
{ {MFG_CLUSTER_ID_SBOX, MFG_SBOX_MANUCODE } };

CONST uint8 zclManuCodeNum = ( sizeof(zclSalesBox_ManuCodeArray) / sizeof(zclSalesBox_ManuCodeArray[0]) );

#if ZCL_DISCOVER
CONST zclCommandRec_t zclSalesBox_Cmds[] =
{
  BASIC_CMD_S_RX,
  IDENTIFY_CMD_S_RX,
  IDENTIFY_CMD_S_TX,
  ONOFF_CMD_S_RX,
  LEVEL_CMD_S_RX,
  SBOX_CMD_S_RX,
  SBOX_CMD_S_TX,
};

CONST uint8 zclCmdsArraySize = ( sizeof(zclSalesBox_Cmds) / sizeof(zclSalesBox_Cmds[0]) );

#endif // ZCL_DISCOVER

/*********************************************************************
 * ATTRIBUTE DEFINITIONS - Uses REAL cluster IDs
 */
CONST zclAttrRec_t zclSalesBox_Attrs[] =
{
  // *** General Basic Cluster Attributes ***
  GEN_BASIC_ATTRS(zclSalesBox),
  GEN_IDENTIFY_ATTRS(zclSalesBox),
  //GEN_ONOFF_ATTRS(zclSalesBox),
  //GEN_LEVEL_ATTRS(zclSalesBox),
  MFG_SBOX_ATTRS(zclSalesBox)
};

uint8 CONST zclSalesBox_NumAttributes = ( sizeof(zclSalesBox_Attrs) / sizeof(zclSalesBox_Attrs[0]) );


CONST zclAttrRec_t zclSensor_Attrs[] =
{
  // *** General Basic Cluster Attributes ***
  GEN_BASIC_ATTRS(zclSalesBox),
  GEN_IDENTIFY_ATTRS(zclSensor),
  GEN_ONOFF_ATTRS(zclSensor),
};

uint8 CONST zclSensor_NumAttributes = ( sizeof(zclSensor_Attrs) / sizeof(zclSensor_Attrs[0]) );

/*********************************************************************
 * SIMPLE DESCRIPTOR
 */
// This is the Cluster ID List and should be filled with Application
// specific cluster IDs.
const cId_t zclSalesBox_InClusterList[] =
{
  ZCL_CLUSTER_ID_GEN_BASIC,
  ZCL_CLUSTER_ID_GEN_IDENTIFY,
  //ZCL_CLUSTER_ID_GEN_ON_OFF,
  //ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL,
  MFG_CLUSTER_ID_SBOX,
};
#define ZCLSALESBOX_MAX_INCLUSTERS   (sizeof(zclSalesBox_InClusterList) / sizeof(zclSalesBox_InClusterList[0]))


const cId_t zclSalesBox_OutClusterList[] =
{
  ZCL_CLUSTER_ID_GEN_BASIC,
};
#define ZCLSALESBOX_MAX_OUTCLUSTERS  (sizeof(zclSalesBox_OutClusterList) / sizeof(zclSalesBox_OutClusterList[0]))

SimpleDescriptionFormat_t zclSalesBox_SimpleDesc =
{
  SALESBOX_ENDPOINT,                  //  int Endpoint;
  ZCL_HA_PROFILE_ID,                     //  uint16 AppProfId;
  MFG_DEVICEID_SBOX,          //  uint16 AppDeviceId; 
  SALESBOX_DEVICE_VERSION,            //  int   AppDevVer:4;
  SALESBOX_FLAGS,                     //  int   AppFlags:4;
  ZCLSALESBOX_MAX_INCLUSTERS,         //  byte  AppNumInClusters;
  (cId_t *)zclSalesBox_InClusterList, //  byte *pAppInClusterList;
  ZCLSALESBOX_MAX_OUTCLUSTERS,        //  byte  AppNumInClusters;
  (cId_t *)zclSalesBox_OutClusterList //  byte *pAppInClusterList;
};


const cId_t zclSensor_InClusterList[] =
{
  ZCL_CLUSTER_ID_GEN_BASIC,
  ZCL_CLUSTER_ID_GEN_IDENTIFY,
  ZCL_CLUSTER_ID_GEN_ON_OFF,
};
#define ZCLSENSOR_MAX_INCLUSTERS   (sizeof(zclSensor_InClusterList) / sizeof(zclSensor_InClusterList[0]))


const cId_t zclSensor_OutClusterList[] =
{
  ZCL_CLUSTER_ID_GEN_BASIC,
};
#define ZCLSENSOR_MAX_OUTCLUSTERS  (sizeof(zclSensor_OutClusterList) / sizeof(zclSensor_OutClusterList[0]))

SimpleDescriptionFormat_t zclSensor_SimpleDesc =
{
  SENSOR_ENDPOINT,                   //  int Endpoint;
  ZCL_HA_PROFILE_ID,                 //  uint16 AppProfId;
  ZCL_HA_DEVICEID_IAS_ZONE,          //  uint16 AppDeviceId; 
  0,            //  int   AppDevVer:4;
  0,                     //  int   AppFlags:4;
  ZCLSENSOR_MAX_INCLUSTERS,         //  byte  AppNumInClusters;
  (cId_t *)zclSensor_InClusterList, //  byte *pAppInClusterList;
  ZCLSENSOR_MAX_OUTCLUSTERS,        //  byte  AppNumInClusters;
  (cId_t *)zclSensor_OutClusterList //  byte *pAppInClusterList;
};

/*********************************************************************
 * GLOBAL FUNCTIONS
 */

/*********************************************************************
 * LOCAL FUNCTIONS
 */
  
void zclSalesBox_ResetAttributesToDefaultValues(void)
{
  int i;
  
  zclSalesBox_LocationDescription[0] = 16;
  for (i = 1; i <= 16; i++)
  {
    zclSalesBox_LocationDescription[i] = ' ';
  }
  
  zclSalesBox_PhysicalEnvironment = PHY_UNSPECIFIED_ENV;
  zclSalesBox_DeviceEnable = DEVICE_ENABLED;
  
#ifdef ZCL_IDENTIFY
  zclSalesBox_IdentifyTime = 0;
  zclSensor_IdentifyTime = 0;
#endif
  
  /* SALESBOX_TODO: initialize cluster attribute variables. */
}

/****************************************************************************
****************************************************************************/


